|
|
|
|
|
|
|
Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA"
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long,
ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long |
|
|
|
|
|
|
|
|
Note that you can place API declarations directly in a form as long as you precede these declaration lines with the Private keyword. |
|
|
|
|
|
|
|
|
Next, create a new method called GetKeyValue to use these API calls and constants. Enter the code from Listing A.5 into the project. |
|
|
|
|
|
|
|
|
Listing A.5. Coding the GetKeyValue function. |
|
|
|
|
|
|
|
|
Public Function GetKeyValue(KeyRoot As Long, KeyName As String, SubKeyRef
As String, ByRef KeyVal As String) As Boolean
Dim i As Long ' Loop Counter
Dim rc As Long ' Return Code
Dim hKey As Long ' Handle To An Open
Registry Key
Dim hDepth As Long '
Dim KeyValType As Long ' Data Type Of A
Registry Key
Dim tmpVal As String ' Tempory Storage
For A Registry Key Value
Dim KeyValSize As Long ' Size Of Registry
Key Variable
'------------------------------------------------------------
' Open RegKey Under KeyRoot {HKEY_LOCAL_MACHINE...}
'------------------------------------------------------------
rc = RegOpenKeyEx(KeyRoot, KeyName, 0, KEY_ALL_ACCESS, hKey) ' Open Registry
Key
If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError ' Handle Error...
tmpVal = String$(1024, 0) ' Allocate Variable
Space
KeyValSize = 1024 ' Mark Variable Size
'------------------------------------------------------------
' Retrieve Registry Key Value...
'------------------------------------------------------------
rc = RegQueryValueEx(hKey, SubKeyRef, 0, _
KeyValType, tmpVal, KeyValSize) ' Get/Create Key
Value
If (rc <> ERROR_SUCCESS) Then GoTo GetKeyError ' Handle Errors
If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then ' Win95 Adds Null
Terminated String...
tmpVal = Left(tmpVal, KeyValSize - 1) ' Null Found, |
|
|
|
|
|